package common.fengkai.filepost;

import com.alibaba.fastjson.JSONObject;
import common.fengkai.filepost.VO.getPdfInfo;
import common.fengkai.filepost.VO.pdfFileInfo;
import common.fengkai.filepost.utils.Base64util;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * 模拟非车简易系统发送请求
 */
public class pdfSave {
       public static void main(String[] args) throws Exception {
           String url = "http://10.30.48.249/api/seal/signfile";
            //String url = "http://10.29.28.3/api/seal/signfile";
           //String url = "http://10.29.31.61:8882/api/seal/signfile";
           String filePath ="C:\\Users\\carry\\Desktop\\非车简易保单测试\\转发_ 回复_ 电子防伪打印原件\\F66701060620200000005.pdf";
/**
 * "C:\\Users\\carry\\Desktop\\项目资料\\非车简易测试文件\\66801060720200000005.pdf"
* {"File":"xxxxxxxxx",
* "FileName":"xxxxxxxxx",
* "sealNames":["印章名1","印章名2"],
* "printlnerIp":"127.0 .0 .1",
* "positionList":[{"x":"220","y":"220"}],
* "keywordList":[{"keyword":"key"}]}
*/
           RestTemplate rest = new RestTemplate();

           try {
               MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
               String encodeBase64File = Base64util.encodeBase64File(filePath);
               pdfFileInfo pdfFileInfo = getPdfInfo.get();
               pdfFileInfo.setPrintlnerIp("9.3.34.7");
               pdfFileInfo.setCopies(1);
               pdfFileInfo.setDuplex("1");
               pdfFileInfo.setFile(encodeBase64File);
               pdfFileInfo.setFileName("0606.pdf");
               JSONObject pdfFileInfoJson = (JSONObject) JSONObject.toJSON(pdfFileInfo);
               System.out.println(pdfFileInfoJson);
               param.add("pdfFileInfo", pdfFileInfoJson);
               //String string = rest.postForObject(url, param, String.class);
               ResponseEntity<String> stringResponseEntity = rest.postForEntity(url, pdfFileInfoJson, String.class);
               System.out.println(stringResponseEntity);
               System.out.println(pdfFileInfoJson.toString());
           } catch (Exception e) {
               e.printStackTrace();
           }


       }
}
